#include <cstdio>
#include <algorithm>

long long const maxn = 100100;
int tim[maxn];
long long all[maxn];
int n, m, k;


bool judge(long long x)
{
    for (long long i = 0; i < n; i++) {
        if (x < tim[i]) return false;
        all[n - i - 1] = x - tim[i];
    }
    /*
    for (long long i = 0; i < n; i++) std::prlong longf("%d ", all[i]);
    stod::prlong longf("\n");
    */
    long long worker = m, spare_tim = 0;
    for (long long i = 0; i < n; i++) {
        long long now = all[i], count = 1;
        for (; i + 1 < n && all[i + 1] == now; i++)
            count++;

        long long t = (now - spare_tim) / k;
        if (worker >= n) return true;
        worker *= ((long long)(1) << t);
        spare_tim += k * t;

        if (worker < count) return false;
        worker -= count;
    }
    return true;
}

int main()
{
    int T; scanf("%d", &T);
    while (T--) {
        scanf("%d %d %d", &n, &m, &k);
        for (long long i = 0; i < n; i++) scanf("%d", &tim[i]);

        std::sort(tim, tim + n);
        long long l = 1, r = 1e9;
        while (l + 1 < r) {
            long long mid = (l + r) / 2;
            if (judge(mid)) r = mid;
            else l = mid;
        }
        if (judge(l)) r = l;
        std::printf("%lld\n", r);
    }
}

